fix(github): serialise empty PR author instead of omitting it - #1020
Conversation
|
Claude finished @vidhu-balad's task in 2m 38s —— View job Code Review
Static analysis
Assessment — looks good ✅This is a clean, minimal fix and the review history converged well.
Minor / non-blocking notes
Nice work strengthening the test in response to review feedback — the JSON-level assertion is the correct way to pin this behaviour. |
|
Another note; same bug class exists for review authors (approvers). In |
| require.NoError(t, err) | ||
| require.Equal(t, "", evidence.Author, |
There was a problem hiding this comment.
This assertion still doesn't guard the actual fix (raised in the earlier review, not yet addressed).
The fix is purely the JSON struct-tag change in types.go (dropping omitempty). But buildPREvidence assigns Author: author verbatim (github.go:316), so require.Equal(t, "", evidence.Author, …) is trivially true regardless of the struct tag — it stays green even if someone re-adds omitempty, which would re-introduce the exact bug this PR fixes.
To pin the behavior, assert on the marshaled JSON so the author key is proven present when empty:
require.NoError(t, err)
require.Equal(t, "", evidence.Author,
"empty PR author login must be preserved")
b, err := json.Marshal(evidence)
require.NoError(t, err)
require.Contains(t, string(b), `"author":""`,
"empty author must be serialised, not omitted")(requires adding "encoding/json" to the import block.)
When the GitHub account of a PR creator is deleted, the GraphQL API returns null for the Author node, resulting in an empty login string. PREvidence.Author has omitempty, so "" is omitted from the JSON payload, causing the server's FoundPullRequestV2.author required-field validation to fail with "input should be a string extra inputs are not permitted". Guard added in buildPREvidence: if author == "", set it to "unknown". Both call sites (PREvidenceForCommitV2 and PREvidenceByPRNumber) pass through this function, so both are covered. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…nknown" Remove the omitempty tag from PREvidence.Author so an empty string is serialised in the JSON payload rather than omitted. Drop the "unknown" fallback in buildPREvidence — the server's FoundPullRequestV2.author accepts an empty string directly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The minimal {URL, State} fixtures were being accepted by the server as
FoundPullRequestV1. Removing omitempty from PREvidence.Author means
author:"" is now always sent, which FoundPullRequestV1 rejects
(extra="forbid"). Update both fixtures to include all required V2
fields, matching what buildPREvidence actually produces.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Empty Commits slice is omitted by omitempty, causing FoundPullRequestV2 validation to fail with "commits: Field required". Add a minimal commit so the slice is non-empty and serialised correctly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The struct-field assertion passes regardless of the omitempty tag. Adding a JSON marshal check pins the actual wire behaviour: if omitempty were re-added to PREvidence.Author the test would fail. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ec85bb4 to
3b2f4da
Compare
Summary
nullfor theAuthornode, resulting inauthor = ""in GoPREvidence.Authorhasomitempty, so an empty string is omitted from the JSON payload entirelyFoundPullRequestV2.authoris a required field — missing it causes validation to fail with"input should be a string extra inputs are not permitted"buildPREvidencesubstitutes"unknown"whenauthor == "", covering bothPREvidenceForCommitV2andPREvidenceByPRNumbercall sitesTest plan
TestBuildPREvidence_EmptyAuthorFallsBackToUnknownadded and passesinternal/githubtests pass (go test ./internal/github/...)go vet ./internal/github/...is clean🤖 Generated with Claude Code